Skip to content

Add dtype helper macro#8140

Open
connortsui20 wants to merge 1 commit into
developfrom
ct/dtype-macro
Open

Add dtype helper macro#8140
connortsui20 wants to merge 1 commit into
developfrom
ct/dtype-macro

Conversation

@connortsui20
Copy link
Copy Markdown
Contributor

Summary

I often have found myself getting annoyed at the amount of boilerplate needed to define different dtypes.

This is a simple macro that autogenerates dtypes and nested dtypes. I specifically exclude struct fields from this macro since people might have different opinions on what the syntax should be.

Also adds a const version of DecimalDType construction since I would like to have the dtype macro fail if we try to construct something bad.

Testing

Basic unit tests, including some deeper nested dtypes.

@connortsui20 connortsui20 added the changelog/chore A trivial change label May 28, 2026
);

// SAFETY: `precision > 0` was asserted above.
let precision = unsafe { NonZero::new_unchecked(precision) };
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the safe ctr?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The safe one returns an option

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this that instead of an assert above.

Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 29, 2026

Merging this PR will improve performance by 19.85%

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚡ 1 improved benchmark
✅ 1265 untouched benchmarks

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation chunked_varbinview_opt_canonical_into[(1000, 10)] 225.4 µs 188.1 µs +19.85%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing ct/dtype-macro (6329248) with develop (1cd5c27)

Open in CodSpeed

Comment on lines +376 to +385
let inner = StructFields::from_iter([("mean", dtype!(f64?)), ("count", dtype!(u32))]);
let outer = StructFields::from_iter([
("id", dtype!(i64)),
("label", dtype!(utf8?)),
("values", dtype!(list(f32)?)),
("codes", dtype!(fixed_size_list(u8?)[4])),
("metrics", dtype!(struct(inner)?)),
]);
let dt = dtype!(struct(outer.clone())?);
assert_eq!(dt, DType::Struct(outer, Nullable));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets add structs!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/chore A trivial change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants